<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Timestamp Converter</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            line-height: 1.5;
            background-color: #f5f5f5;
            color: #333;
            padding: 1rem;
            min-height: 100vh;
        }

        .container {
            max-width: 500px;
            margin: 0 auto;
            background: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        h1 {
            font-size: 1.5rem;
            margin-bottom: 1.5rem;
            color: #1a1a1a;
        }

        .input-group {
            margin-bottom: 1.5rem;
        }

        label {
            display: block;
            font-size: 0.875rem;
            font-weight: 500;
            margin-bottom: 0.5rem;
            color: #4a4a4a;
        }

        input {
            width: 100%;
            padding: 0.75rem;
            font-size: 1rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            transition: border-color 0.2s, box-shadow 0.2s;
        }

        input:focus {
            outline: none;
            border-color: #2563eb;
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
        }

        .time-display {
            margin-bottom: 1rem;
        }

        .time-display-label {
            font-size: 0.875rem;
            font-weight: 500;
            margin-bottom: 0.5rem;
            color: #4a4a4a;
        }

        .time-display-value {
            background-color: #f8f9fa;
            padding: 0.75rem;
            border-radius: 4px;
            font-family: monospace;
            font-size: 0.875rem;
            word-wrap: break-word;
        }

        @media (max-width: 480px) {
            body {
                padding: 0.5rem;
            }

            .container {
                padding: 1rem;
            }

            input {
                font-size: 16px; /* Prevents zoom on mobile */
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Timestamp Converter</h1>
        
        <div class="input-group">
            <label for="timestamp">Unix Timestamp</label>
            <input 
                type="text" 
                id="timestamp" 
                placeholder="Enter Unix timestamp..."
                autocomplete="off"
            >
        </div>

        <div class="time-display">
            <div class="time-display-label">UTC Time:</div>
            <div id="utcTime" class="time-display-value"></div>
        </div>

        <div class="time-display">
            <div class="time-display-label">Local Time:</div>
            <div id="localTime" class="time-display-value"></div>
        </div>
    </div>

    <script>
        const timestampInput = document.getElementById('timestamp');
        const utcTimeDiv = document.getElementById('utcTime');
        const localTimeDiv = document.getElementById('localTime');

        function formatUTCDate(date) {
            return date.toLocaleString('en-US', {
                weekday: 'long',
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                timeZone: 'UTC',
                timeZoneName: 'short'
            });
        }

        function formatLocalDate(date) {
            return date.toLocaleString('en-US', {
                weekday: 'long',
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit',
                timeZoneName: 'short'
            });
        }

        function updateTimes() {
            const timestamp = timestampInput.value.trim();
            
            if (!timestamp) {
                utcTimeDiv.textContent = '—';
                localTimeDiv.textContent = '—';
                return;
            }

            // Handle both seconds and milliseconds
            const ms = timestamp.length <= 10 ? timestamp * 1000 : timestamp;
            const date = new Date(Number(ms));

            if (isNaN(date.getTime())) {
                utcTimeDiv.textContent = 'Invalid timestamp';
                localTimeDiv.textContent = 'Invalid timestamp';
                return;
            }

            utcTimeDiv.textContent = formatUTCDate(date);
            localTimeDiv.textContent = formatLocalDate(date);
        }

        timestampInput.addEventListener('input', updateTimes);
        
        // Initialize with current timestamp
        timestampInput.value = Math.floor(Date.now() / 1000);
        updateTimes();
    </script>
</body>
</html>
